﻿using System;
using Android.App;
using Android.Content;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;

namespace droid
{
    [Activity(Label = "RASP", MainLauncher = true, Icon = "@drawable/icon")]
    public class MainActivity : Activity
    {
        Button getCharactersButton;

        string name = string.Empty;

        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
            SetContentView(Resource.Layout.Main);

            if (bundle != null)
            {
                name = bundle.GetString("Username", string.Empty);
            }

            ////Debug
            //name = "Myggdräpe";

            // Get our button from the layout resource,
            // and attach an event to it
            getCharactersButton = FindViewById<Button>(Resource.Id.GetCharacters);

            getCharactersButton.Click += delegate
            {
                var selectActivity = new Intent(this, typeof(SelectActivity));
                name = FindViewById<TextView>(Resource.Id.editName).Text;
                selectActivity.PutExtra("Username", name);
                if (bundle != null) bundle.Remove("CharacterName");
                StartActivity(selectActivity);
            };

            if (!String.IsNullOrWhiteSpace(name))
            {
                var sel = new Intent(this, typeof(SelectActivity));
                //name = FindViewById<TextView>(Resource.Id.editName).Text;
                sel.PutExtra("Username", name);
                StartActivity(sel);
                return;
            }
            
        }


        protected override void OnSaveInstanceState(Bundle outState)
        {
            outState.PutString("Username", name);

            // always call the base implementation!
            base.OnSaveInstanceState(outState);
        }
    }
}

